﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DemoGame_bird2._0
{
    /// <summary>
    /// 游戏对象:小鸟
    /// </summary>
    class LittleBird
    {

        //绘制小鸟
        public Rectangle Rectangle { get; set; }
        public int Y { get; set; }

        //初始化不同飞翔状态的小鸟图片组
        public int BirdWings { get; set; }

        //定义纵向速度
        private int SpeedY;

        //初始化y坐标的单位变化量
        private const int step = -50;


        ///初始化小鸟
        public LittleBird(Rectangle rec)
        {
            Rectangle = rec;

            //小鸟纵向下落速度为10
            SpeedY = 10;    
            
        }



        /// <summary>
        /// 绘制LittleBird
        /// </summary>
        /// <param name="g"></param> 
        private static Image[] images =
        { 
            //不同飞翔状态的小鸟图片数组
            Properties.Resources._0,
            Properties.Resources._1,
            Properties.Resources._2

        };
       
        public void Draw(Graphics g)
        {
            // 依据选择，绘制不同飞翔状态的小鸟图片
            switch (this.BirdWings)
            {
                case 0:
                    g.DrawImage(images[1], Rectangle);
                    break;

                case 1:
                    g.DrawImage(images[2], Rectangle);
                    break;

                case 2:
                    g.DrawImage(images[0], Rectangle);
                    break;
            }


            this.BirdWings++;

            if (this.BirdWings >= 3)
            {
                this.BirdWings = 0;
            }
        }




        /// <summary>
        /// 处理“小鸟移动（仅上下移动）”事件
        /// </summary>
        public void Move()
        {
            this.Rectangle = new Rectangle(this.Rectangle.X,
                                           this.Rectangle.Y + SpeedY,
                                           Rectangle.Width,
                                           Rectangle.Height);

        }



        /// <summary>
        /// 处理“键盘”事件
        /// </summary>
        /// <param name="key"></param>
        public void KeyDown(String key)
        {
            //H键负责控制小鸟的上升移动
            if (key == "H")  
            Rectangle = new Rectangle(Rectangle.X,
                                      Rectangle.Y + step,
                                      Rectangle.Width,
                                      Rectangle.Height);
        }

    }
}